<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    
<!--    count(//xs:element[not(empty(@name) )])
    
    distinct-values(//xs:attribute/@name)
-->    
   <xsl:output method="text" encoding="UTF-8"></xsl:output>
   
   <xsl:variable name="xlinkGroups" select="doc('http://www.loc.gov/standards/xlink/xlink.xsd')//xs:attributeGroup" />
   
   <xsl:template match="/">
       
        <!--<xsl:for-each select="distinct-values(//namespace::*)">
            <xsl:value-of select="concat('@namespace ''', .,''';&#xA;')"/>
        </xsl:for-each>-->
       @namespace 'urn:isbn:1-931666-33-4';
       @namespace xlink 'http://www.w3.org/1999/xlink';
       @namespace xml 'http://www.w3.org/XML/1998/namespace';
       
        
       <xsl:apply-templates/>
       
   </xsl:template>
   
   
    <xsl:template match="xs:element[not(empty(@name) )]">
        <xsl:value-of select="./@name"/> <xsl:text>{</xsl:text>
        <xsl:text>display: block;</xsl:text>
        <xsl:text>margin-left: 20px;</xsl:text>
        <xsl:text>border: 1px #787878 solid;</xsl:text>
        <xsl:text>padding: 10px;</xsl:text>
        <xsl:text>}</xsl:text>
        
        <xsl:value-of select="./@name"/><xsl:text>:before{</xsl:text>
            <xsl:text>content: "</xsl:text><xsl:value-of select="./@name"/><xsl:text>" </xsl:text>
                <xsl:text>" ("</xsl:text>
                    <xsl:for-each select="./*/xs:attribute/@ref">
                        <xsl:text>" - </xsl:text><xsl:value-of select="."/>: " attr(<xsl:value-of select="replace(., ':','|')"/>)       
                    </xsl:for-each>
                    <xsl:for-each select="./*/xs:attribute/@name">
                        <xsl:text>" - </xsl:text><xsl:value-of select="."/>: " attr(<xsl:value-of select="replace(., ':','|')"/>)       
                    </xsl:for-each>
                    
                    <xsl:for-each select="./*/xs:attributeGroup">
                        <xsl:variable name="attributeGroupName" select="./@ref"/>
                        
                        <xsl:for-each select="//xs:attributeGroup[@name eq $attributeGroupName]/xs:attribute/@name">
                            <xsl:text>" - </xsl:text><xsl:value-of select="."/>: " attr(<xsl:value-of select="replace(., ':','|')"/>) 
                        </xsl:for-each>
                        
                        <xsl:for-each select="//xs:attributeGroup[@name eq $attributeGroupName]/xs:attribute/@ref">
                            <xsl:text>" - </xsl:text><xsl:value-of select="."/>: " attr(<xsl:value-of select="replace(., ':','|')"/>) 
                        </xsl:for-each>

                        <xsl:message>
                            <xsl:value-of select="substring-after($attributeGroupName, ':')"/>
                            <xsl:value-of select="$xlinkGroups[@name eq substring-after($attributeGroupName, ':')]/xs:attribute[1]/@name"></xsl:value-of>
                        </xsl:message>
                        
                        <xsl:for-each select="$xlinkGroups[@name eq substring-after($attributeGroupName, ':')]/xs:attribute/@name">
                            <xsl:text>" - </xsl:text><xsl:value-of select="."/>: " attr(<xsl:value-of select="replace(., ':','|')"/>) 
                        </xsl:for-each>
                        
                        <xsl:for-each select="$xlinkGroups[@name eq substring-after($attributeGroupName, ':')]/xs:attribute/@ref">
                            <xsl:text>" - </xsl:text><xsl:value-of select="."/>: " attr(<xsl:value-of select="replace(., ':','|')"/>) 
                        </xsl:for-each>
                        
                    </xsl:for-each>
        
                <xsl:text>"): "</xsl:text>
            <xsl:text>;</xsl:text>
        <xsl:text>}</xsl:text>
    </xsl:template>
        
   
</xsl:stylesheet>